package jpair.pairing;

import jpair.api.Field;
import jpair.api.FieldElement;




/**
 * Predefined pairing parameters 
 * 
 *      
 * @author Changyu Dong
 * @version 1.0
 */
public class Predefined {
	/**
	 * ec is a super-singular curve {@code Y^2=X^3+X} over a 512-bit finite field, 
	 * twisted curve is the same, 
	 * order of G1 is 160-bit, 
	 * the overall security is roughly the same as 1024-bit RSA.
	 *      
	 */
	public static TatePairing ssTate160(){
		BigInt p = new BigInt("8BA2A5229BD9C57CFC8ACEC76DFDBF3E3E1952C6B3193ECF5C571FB502FC5DF410F9267E9F2A605BB0F76F52A79E8043BF4AF0EF2E9FA78B0F1E2CDFC4E8549B",16);
		Field field=new Fp(p);
				
		BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001",16);
		
		BigInt cof =  new BigInt("117454A4537B38AF9F9159D8EDBFB7E7C7C2E48760E930A461D5F451F9D9210DC70095F4B241FF57F1BB0549C",16);
		
		//curve 
		//y^2=x^3+x
	
	FieldElement a = field.getOne();
        //       FieldElement a = field.negate(BigInt.valueOf(3));
		FieldElement b = field.getZero();
		EllipticCurve ec = new EllipticCurve(field,a,b);

		
		return new TatePairing(ec,orderOfGroup,cof);
		
		
	}
        
        public static TatePairing bnTate160(){
		BigInt p = new BigInt("8BA2A5229BD9C57CFC8ACEC76DFDBF3E3E1952C6B3193ECF5C571FB502FC5DF410F9267E9F2A605BB0F76F52A79E8043BF4AF0EF2E9FA78B0F1E2CDFC4E8549B",16);
		Field field=new Fp(p);
				
		BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001",16);
		
		BigInt cof =  new BigInt("117454A4537B38AF9F9159D8EDBFB7E7C7C2E48760E930A461D5F451F9D9210DC70095F4B241FF57F1BB0549C",16);
		
		//curve 
		//y^2=x^3+x
	
		FieldElement a = field.getOne();
               FieldElement b = field.negate(BigInt.valueOf(2));
		//FieldElement b = field.getZero();
		EllipticCurve ec = new EllipticCurve(field,a,b);

		
		return new TatePairing(ec,orderOfGroup,cof);
		
		
	}
        
        
	/**
	 * Predefined compressed tate pairing.
	 * ec is a super-singular curve {@code Y^2=X^3+X} over a 512-bit finite field, 
	 * twisted curve is the same, 
	 * order of G1 is 160-bit, 
	 * the overall security is roughly the same as 1024-bit RSA.
	 *      
	 */
	public static CompressedTatePairing ssTate160_C(){
		BigInt p = new BigInt("8BA2A5229BD9C57CFC8ACEC76DFDBF3E3E1952C6B3193ECF5C571FB502FC5DF410F9267E9F2A605BB0F76F52A79E8043BF4AF0EF2E9FA78B0F1E2CDFC4E8549B",16);
		Field field=new Fp(p);
				
		BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001",16);
		
		BigInt cof =  new BigInt("117454A4537B38AF9F9159D8EDBFB7E7C7C2E48760E930A461D5F451F9D9210DC70095F4B241FF57F1BB0549C",16);
		
		//curve 
		//y^2=x^3+x
	
		FieldElement a = field.getOne();
		FieldElement b = field.getZero();
		EllipticCurve ec = new EllipticCurve(field,a,b);

		
		return new CompressedTatePairing(ec,orderOfGroup,cof);
		
		
	}
        
        	 /**
	 * ec is a non-super-singular curve {@code Y^2=X^3-3X+B} over a 512-bit finite field, 
	 * twisted curve is{@code Y^2=X^3-3X-B}, 
	 * order of G1 is 160-bit, 
	 * the overall security is roughly the same as 1024-bit RSA.
	 */
        
	public static TatePairing nssTate160(){
		BigInt p = new BigInt("8D5006492B424C09D2FEBE717EE382A57EBE3A352FC383E1AC79F21DDB43706CFB192333A7E9CF644636332E83D90A1E56EFBAE8715AA07883483F8267E80ED3",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("11AA00C9256849813A5FD7CE2FDC7054AFD7809E7F7FD948C4B9C1C1E76FFEFF4ECAB83C950112DECB41D6EDA",16);
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("609993837367998001C95B87A6BA872135E26906DB4C192D6E038486177A3EDF6C50B9BB20DF881F2BD05842F598F3E037B362DBF89F0A62E5871D41D951BF8E",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	}   
        
	/**
	 * Predefined compressed tate pairing.
	 * ec is a non-super-singular curve {@code Y^2=X^3-3X+B} over a 512-bit finite field, 
	 * twisted curve is{@code Y^2=X^3-3X-B}, 
	 * order of G1 is 160-bit, 
	 * the overall security is roughly the same as 1024-bit RSA.
         */
     
      	
	public static CompressedTatePairing nssTate160_C(){
		BigInt p = new BigInt("8D5006492B424C09D2FEBE717EE382A57EBE3A352FC383E1AC79F21DDB43706CFB192333A7E9CF644636332E83D90A1E56EFBAE8715AA07883483F8267E80ED3",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("8000000000000000000000000000000000020001",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("11AA00C9256849813A5FD7CE2FDC7054AFD7809E7F7FD948C4B9C1C1E76FFEFF4ECAB83C950112DECB41D6EDA",16);
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("609993837367998001C95B87A6BA872135E26906DB4C192D6E038486177A3EDF6C50B9BB20DF881F2BD05842F598F3E037B362DBF89F0A62E5871D41D951BF8E",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);

		
		return new CompressedTatePairing(ec,orderOfGroup,cof);
	}

        
        
    
        
        	/**
	 * Predefined compressed tate pairing.
	 * ec is a non-super-singular curve {@code Y^2=X^3-3X+B} over a 512-bit finite field, 
	 * twisted curve is{@code Y^2=X^3-3X-B}, 
	 * order of G1 is 192-bit, 
	 * the overall security is roughly the same as 2048-bit RSA.
	 */
	public static TatePairing nssTate192(){
		BigInt p = new BigInt("F9A4B6FF71ED6D6A1517BDD118ECE82C0B27092A8ECBDAE421528F2B410037715493BDF84B6D13198B7FB09E758C9513220CD2A9CA72466B7647BFA8EB7AD43B",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("800000000000000000000000000000000000000000000005",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("1F3496DFEE3DADAD42A2F7BA231D9D058164E12551D97B5B4C1C6D2619B73E299034CA79AA45802C2",16);
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("AD5DD6C3F18FEEBE6BC8110E833FB0E649A6C2E127362C8A2B0C88857E7AC90D5A1546038DF3FE7CFFCCC018ACA7F425B9122B4FF3C2F3A447E59CBCBBFD490E",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	}   
        
              	/**
	 * Predefined compressed tate pairing.
	 * ec is a non-super-singular curve {@code Y^2=X^3-3X+B} over a 512-bit finite field, 
	 * twisted curve is{@code Y^2=X^3-3X-B}, 
	 * order of G1 is 224-bit, 
	 * the overall security is roughly the same as 4096-bit RSA.
	 */
	public static TatePairing nssTate224(){
		BigInt p = new BigInt("AA9FC4D7DEA6D871B209E28072B065EBA8B59916C44D568E67D64FDA3EC5B096263BACD0689C21CB7C3E938EE44366FD69F42DEE576C171E3EE854D6EEA537F3",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("80000000000000000000000000000000000000000000000000002001",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("1553F89AFBD4DB0E36413C500E560CBD7516B322D889AAD1CCFAC4A61F0A05E7965A31ED4",16);
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("966DE4DFE37FB4E2679B61E9F0FE858EAEBF294FB15922628C96A8EA77DF0608D4DB1EA77476AC6E083649379F19127D61D316FF130AB8D693DB607A66C51541",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	}   
        
        
      
        
        
        
        
        
        
        /*********************************************/
        
        
        
        
        
        public static TatePairing ssTate192(){
		BigInt p = new BigInt("F9A4B6FF71ED6D6A1517BDD118ECE82C0B27092A8ECBDAE421528F2B410037715493BDF84B6D13198B7FB09E758C9513220CD2A9CA72466B7647BFA8EB7AD43B",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("800000000000000000000000000000000000000000000005",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("1F3496DFEE3DADAD42A2F7BA231D9D058164E12551D97B5B4C1C6D2619B73E299034CA79AA45802C2",16);
		
		
		
		FieldElement a = field.getOne();
        //       FieldElement a = field.negate(BigInt.valueOf(3));
		FieldElement b = field.getOne();
		EllipticCurve ec = new EllipticCurve(field,a,b);
		
		
		//FieldElement a4 = field.negate(BigInt.valueOf(3));
	//	FieldElement a6 = new BigInt("AD5DD6C3F18FEEBE6BC8110E833FB0E649A6C2E127362C8A2B0C88857E7AC90D5A1546038DF3FE7CFFCCC018ACA7F425B9122B4FF3C2F3A447E59CBCBBFD490E",16);
		//EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	} 
        public static TatePairing mnt(){
		BigInt p = new BigInt("7DDCA613A2E3DDB1749D0195BB9F14CF44626303",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("FBB94C2745C7BB62E93BBADB1D6BFF48B23BE531",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("3EEE5309D171EED8BA4E12DEF44414FD17D369B7",16);
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("21C3F3AC7864D1F1F99273D0F828D3657D8CFD4E",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	}  
        
     
        
                
	public static TatePairing secp192k1(){
		BigInt p = new BigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37",16);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D",16);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("01",16);
		
		FieldElement a4 = new BigInt("000000000000000000000000000000000000000000000000",16);
		FieldElement a6 = new BigInt("000000000000000000000000000000000000000000000003",16);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		
		return new TatePairing(ec,orderOfGroup,cof);
	}   
        
        
        public static TatePairing pf177(){
		BigInt p = new BigInt("18211650803969472064493264347375950045934254696657090420726230043203803",10);
		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt orderOfGroup = new BigInt("18211650803969472064493264347375949776033155743952030750450033782306651",10);
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("1",10);
		
		
		FieldElement a4 = field.negate(BigInt.valueOf(3));
		FieldElement a6 = new BigInt("15748668094913401184777964473522859086900831274922948973320684995903275",10);
		EllipticCurve ec = new EllipticCurve(field,field.getZero(),field.getZero(),field.getZero(),a4,a6);
		return new TatePairing(ec,orderOfGroup,cof);
	}  
        
        
        
        
            
        public static TatePairing bn256(){
		BigInt p = new BigInt("fffffffffffcf0cd46e5f25eee71a49f0cdc65fb12980a82d3292ddbaed33013",16);

		Field field=new Fp(p);
		//order =2^159+2^17+1		
		BigInt r = new BigInt("fffffffffffcf0cd46e5f25eee71a49e0cdc65fb1299921af62d536cd10b500d",16);
     
		//BigInt orderOfE= new BigInt("11711338024714009669995700965425239711927177698599625717955894184681899877662611539569996945969293708404400344208273812850399351303651875378098503534075638");
		
		//co-factor
		
		BigInt cof = new BigInt("11",16);
		//BigInt cof = p.divide(orderOfGroup);
	
       
      
           	FieldElement a = field.getZero();
   
		FieldElement b = new BigInt("3",16);
		EllipticCurve ec = new EllipticCurve(field,a,b);
                
               
                
		return new TatePairing(ec,r,cof);
	}  
        
        
     
        
}
